<div class="setting com_width">
    <?php include PROJECT_PATH . 'Application/View/menu.tpl.php';?>
    <div class="menu_head"></div>
    <div class="right">
        <div class="modeladd">
            <div class="info">
                <span class="title">模特姓名:</span>
                <input id="modelname" class="text text_big" type="text" value="" />
            </div>
            <div class="info">
                <span class="title">别<span class="title_middle"></span>名:</span>
                <input id="nickname" class="text text_middle" type="text" value="" />
            </div>
            <div class="info">
                <span class="title">国<span class="title_middle"></span>籍:</span>
                <input id="country" class="text text_middle" type="text" value="" />
            </div>
            <div class="info">
                <span class="title">类<span class="title_middle"></span>型:</span>
                <select id="style" class="select flg text hover">
                	<?php foreach ($modelStyle as $k=>$v){?>
                    <option value="<?=$k?>" ><?=$v?></option>
                    <?php }?>
                </select>
            </div>
            <div class="info">
                <span class="title">身<span class="title_middle"></span>高:</span>
                <input id="height" class="text text_small" type="text" value="" />
            </div>
            <div class="info">
                <span class="title">胸<span class="title_middle"></span>围:</span>
                <input id="bust" class="text text_small" type="text" value="" />
            </div>
            <div class="info">
                <span class="title">腰<span class="title_middle"></span>围:</span>
                <input id="waist" class="text text_small" type="text" value="" />
            </div>
            <div class="info">
                <span class="title">臀<span class="title_middle"></span>围:</span>
                <input id="hip" class="text text_small" type="text" value="" />
            </div>
            <div class="info">
                <span class="title">鞋<span class="title_middle"></span>码:</span>
                <input id="shoescode" class="text text_small" type="text" value="" />
            </div>
            <div class="info">
                <span class="title company">母公司:</span>
                <input id="company" class="text text_middle" type="text" value="" />
            </div>
            <div class="info">
                <span class="title">在京时间:</span>
                <input id="beijingstart" class="time text hover" type="text" value="<?=Model_Common::getFormatTimeYMD()?>" onClick="WdatePicker({readOnly:true,lang:'zh-cn'})" />
                <span class="fromto">至</span>
                <input id="beijingend" class="time text hover" type="text" value="<?=Model_Common::getFormatTimeYMD()?>" onClick="WdatePicker({readOnly:true,lang:'zh-cn'})" />
            </div>
            <div class="info">
                <span class="title">休假时间:</span>
                <input id="illstart" class="time text hover" type="text" value="" onClick="WdatePicker({readOnly:true,lang:'zh-cn'})" />
                <span class="fromto">至</span>
                <input id="illend" class="time text hover" type="text" value="" onClick="WdatePicker({readOnly:true,lang:'zh-cn'})" />
            </div>
            <div class="info">
                <span class="title floatleft">休假信息:</span>
                <textarea id="illinfo" class="multtext"></textarea>
            </div>
            <div class="info" id="modelimgwapper">
                <div><span class="title">模特图片列表如下:</span></div>
            </div>
            <div class="info">
                <span class="title">上传图片:</span>
                <input id="upload" name="upload" type="file" value="" />
                <span id="imgadd" class="btn imgadd">上传</span>
            </div>
            <div class="errmsg" id="errmsg"></div>
            <div class="info">
                <input id="modeladd" class="btn btn_add btn_input" type="button" value="添 加 模 特">
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    $("#modelname").focus();
    $("#modeladd").click(function(){
        $("#errmsg").text("");
        modelimgs = "";
        $('.modelimg').each(function(){
            modelimgs += $(this).attr("value");
            modelimgs += ",";
            
        });
        $.ajax({
              url: "http://<?=HOST?>/model/doAdd",
              cache: false,
              timeout:10000,
              type: "POST",
              data: {
                  modelname:$("#modelname").val(),
                  nickname:$("#nickname").val(),
                  country:$("#country").val(),
                  height:$("#height").val(),
                  bust:$("#bust").val(),
                  waist:$("#waist").val(),
                  hip:$("#hip").val(),
                  shoescode:$("#shoescode").val(),
                  company:$("#company").val(),
                  beijingstart:$("#beijingstart").val(),
                  beijingend:$("#beijingend").val(),
                  illstart:$("#illstart").val(),
                  illend:$("#illend").val(),
                  illinfo:$("#illinfo").val(),
                  style:$("#style").val(),
                  media:modelimgs
              },
              dataType: "json",
              beforeSend: function() {
                  disableHTML(true, '请稍等，处理中……', true);
              },
              success: function(data) {
                  if(data.errCode != 0){
                      disableHTML(true, data.errMsg, false);
                      setTimeout(disableHTML,2000);
                        $("#errmsg").text(data.errMsg);
                        $("#modelname").focus();
                  }else{
                      disableHTML(true, '添加成功，跳转中……', true);
                      setTimeout("location.href = 'http://<?=HOST?>/model/list'", 500);
                  }
              },
              error:function(){
                      disableHTML(true, "请求出错，请重试或联系系统管理员", false);
                      setTimeout(disableHTML,2000);
                      changeAuthCode();
                  }
            });
    });
    $("#imgadd").click(function (){
        ajaxFileUpload();
        
    });
    function ajaxFileUpload()
    {
        $("#upload").ajaxStart(function(){
            $("#errmsg").text("");
            disableHTML(true, '请稍等，上传中……', true);
        })
        $.ajaxFileUpload
        (
            {
                url:"http://<?=HOST?>/model/doUpload", 
                secureuri:false,
                fileElementId:'upload',
                dataType: 'json',
                success: function (data, status)
                {
                    if(data.errCode != 0){
                        disableHTML(true, data.errMsg, false);
                        setTimeout(disableHTML,2000);
                        $("#errmsg").text(data.errMsg);
                      }else{
                        disableHTML(true, '上传成功', false);
                        $("#upload").val("");
                        setTimeout(disableHTML,1000);
                        url = '<?=UPLOAD_PATH?>/' + data.name;
                        img = "<div><input class='modelimg nodisplay' value='" + data.name + "'/><span><img style='max-width:550px;' src='" + url + "'></span><span style='margin-left:8px;' class='btn' onclick='$(this).parent().remove()'>删除</span></div>"
                        $("#modelimgwapper").append(img);
                      }
                },
                error: function (data, status, e)
                {
                      disableHTML(true, "请求出错，请重试或联系系统管理员", false);
                      setTimeout(disableHTML,2000);
                }
            }
        )
        
        return false;

    }  
</script>
